//
//  CSSearchSaleCell.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/11/18.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSSearchSaleCell.h"

#import "TSaleInfoModel.h"

#import "TSaleInfoDAL.h"

@interface CSSearchSaleCell ()

/// 数据源
@property (nonatomic, strong) NSArray<TSaleInfoModel *> *saleListSearch;

//lblIndex
@property(nonatomic,weak) UILabel * lblIndex;
@property(nonatomic,weak) UILabel * lblName;
@property(nonatomic,weak) UILabel * lblUnitCountBig;
@property(nonatomic,weak) UILabel * lblUnitCountSmall;
@property(nonatomic,weak) UILabel * lblUnitPriceBig;
@property(nonatomic,weak) UILabel * lblUnitPriceSmall;
@property(nonatomic,weak) UILabel * lblProducedDate;


@end

@implementation CSSearchSaleCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - methods


- (void)distributeWithDict:(NSDictionary *)dict {
    // @{@"index":index, @"saleModelDetail":saleModelDetail}
    TSaleInfoModel * saleModel = dict[@"saleModelDetail"];
    
    NSArray * unitArr = [saleModel.sUnit componentsSeparatedByString:@","];
    NSArray * unitCountArr = [saleModel.sCount componentsSeparatedByString:@","];
    NSArray * unitPriceArr = [saleModel.sPrice componentsSeparatedByString:@","];
    
    self.lblIndex.text = [NSString stringWithFormat:@"%d", ([dict[@"index"] intValue] + 1)];
    self.lblName.text = saleModel.sName;
    self.lblUnitCountBig.text = [NSString stringWithFormat:@"%@%@", unitCountArr[0], unitArr[0]];
    self.lblUnitCountSmall.text = [NSString stringWithFormat:@"%@%@", unitCountArr[1], unitArr[1]];
    self.lblUnitPriceBig.text = [NSString stringWithFormat:@"%@/%@", unitPriceArr[0], unitArr[0]];
    self.lblUnitPriceSmall.text = [NSString stringWithFormat:@"%@/%@", unitPriceArr[1], unitArr[1]];
    self.lblProducedDate.text = [saleModel.sCreateTime subStringFrontOfKey:@" "];

}

#pragma markl - setupUI
-(void) setupUI {
    //lblIndex
    UILabel * lblIndex = [UILabel gx_labelWithText:@"1" fontSize:11 color:[UIColor whiteColor]];
    [self.contentView addSubview:lblIndex];
    
    lblIndex.backgroundColor = [UIColor orangeColor];
    lblIndex.textAlignment = NSTextAlignmentCenter;
    
    [lblIndex mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(self.contentView).offset(2);
        make.size.mas_offset(CGSizeMake(20, 20));
    }];
    
    //lblName
    UILabel * lblName = [UILabel gx_labelWithText:@"牛奶150ml" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblName];
    
    [lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblIndex);
        make.leading.equalTo(lblIndex.mas_trailing).offset(2);
        make.width.mas_lessThanOrEqualTo([UIScreen mainScreen].bounds.size.width * 2/5);
    }];
    
    //lblUnitCountBig
    UILabel * lblUnitCountBig = [UILabel gx_labelWithText:@"2箱" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblUnitCountBig];
    
    [lblUnitCountBig mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblIndex);
//        make.leading.equalTo(self.contentView).mas_offset([UIScreen mainScreen].bounds.size.width * 0.5);
        make.size.mas_offset(CGSizeMake(40, 20));
    }];
    
    //lblUnitCountSmall
    UILabel * lblUnitCountSmall = [UILabel gx_labelWithText:@"1瓶" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblUnitCountSmall];
    
    [lblUnitCountSmall mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblUnitCountBig.mas_bottom).offset(2);
        make.size.leading.equalTo(lblUnitCountBig);
    }];
    
    //lblUnitPriceBig
    UILabel * lblUnitPriceBig = [UILabel gx_labelWithText:@"230.00/箱" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblUnitPriceBig];
    
//    lblUnitPriceBig.backgroundColor = [UIColor orangeColor];
    
    [lblUnitPriceBig mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView).offset(8);
//        make.top.equalTo(lblUnitCountBig);
        make.top.equalTo(lblIndex);
        make.leading.equalTo(lblUnitCountBig.mas_trailing).offset(10);
        make.width.mas_offset(80);
        make.height.offset(20);
    }];
    
    //lblUnitPriceSmall
    UILabel * lblUnitPriceSmall = [UILabel gx_labelWithText:@"20.81/瓶" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblUnitPriceSmall];
    
//    lblUnitPriceSmall.backgroundColor = [UIColor orangeColor];
    
    [lblUnitPriceSmall mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lblUnitPriceBig.mas_bottom).offset(5);
        make.size.leading.equalTo(lblUnitPriceBig);
    }];
    
    //lblProducedDate 生产日期
    UILabel * lblProducedDate = [UILabel gx_labelWithText:@"08-08-08" fontSize:11 color:[UIColor blackColor]];
    [self.contentView addSubview:lblProducedDate];
    
    [lblProducedDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.trailing.equalTo(self.contentView);
        make.width.offset(80);
        make.leading.equalTo(lblUnitPriceBig.mas_trailing).offset(5);
        make.bottom.equalTo(lblUnitPriceSmall);
    }];
    
//    // contentView
//    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.leading.trailing.equalTo(self);
//        make.bottom.equalTo(lblUnitPriceSmall.mas_bottom).offset(20);
//    }];
    
    //
    self.lblIndex = lblIndex;
    self.lblName = lblName;
    self.lblUnitCountBig = lblUnitCountBig;
    self.lblUnitCountSmall = lblUnitCountSmall;
    self.lblUnitPriceBig = lblUnitPriceBig;
    self.lblUnitPriceSmall = lblUnitPriceSmall;
    self.lblProducedDate = lblProducedDate;
}


#pragma mark - setter & getter

- (void)setDataDictSaleCell:(NSDictionary *)dataDictSaleCell {
    _dataDictSaleCell = dataDictSaleCell;
    
    [self distributeWithDict:dataDictSaleCell];
}
























@end
